<template>
<span class="opera_extend-wrapper">
  <template v-if="ctl=='Hproduct'">
    <button v-if="col.btns.TOCK" class="ui primary circular icon button mini" @click.stop.prevent="Hproduct_tock(col.val)" :title="col.btns.TOCK"><i class="icon send"></i></button>
    <button v-if="col.btns.INFO" class="ui primary  button mini" @click.stop.prevent="Hproduct_info(col.val)">{{col.btns.INFO}}</button>

  </template>
  <template v-if="ctl=='Whprod'">
    <button v-if="col.btns.CKSPINFO" class="ui  button mini" @click.stop.prevent="Whprod_info(col.val)">{{col.btns.CKSPINFO}}</button>

  </template>
  <template v-if="ctl=='Export'">
    <button v-if="col.btns.EXPORT_GETFIELDS" class="ui  button mini" @click.stop.prevent="Export_getFields(col.val)">{{col.btns.getFields}}</button>

  </template>
  <template v-if="ctl=='cache_models'">
    <button v-if="col.btns.CACHE" class="ui  button mini" @click.stop.prevent="cache_models_CACHE(col.val)">{{col.btns.CACHE}}</button>
    <button v-if="col.btns.CLAER_CACHE" class="ui  button mini" @click.stop.prevent="cache_models_CLAER_CACHE(col.val)">{{col.btns.CLAER_CACHE}}</button>

  </template>
  <template v-if="ctl=='Taskcom'">
    <!--&&isMineDownload-->
    <button v-if="col.btns.Download&&has_file_url" class="ui  button mini" @click.stop.prevent="Taskcom_Download(col.val)">{{col.btns.Download}}</button>
    <button v-if="col.btns.showParams&&is_admin" class="ui  button mini" @click.stop.prevent="Taskcom_showParams(col.val)">{{col.btns.showParams}}</button>
  </template>
  <template v-if="ctl=='Trodetail'">
    <button v-if="col.btns.ADD_TAIL_LOG" class="ui  button mini" @click.stop.prevent="Trodetail_ADD_TAIL_LOG(col.val)">{{col.btns.EXPORT_GETFIELDS}}</button>

  </template>
</span>
</template>
<script>
import tool from 'src/util/tool';
import util from '_util/index';
import logic from '_logic';
import model from '_model';
import RP from '_common/show_com';


export default {
  data() {
    return {
      isMineDownload:false,
      detail_info:null,
      Taskcom_info:null
    }
  },
  watch: {
    _id:function (val,old) {
      if(val&&val!=old) {
        this.myinit();

      }
    }
  },
  computed: {

    ctl(){
      return this.$route.query.ctl;
    },
    _id(){
      return this.col.val;
    },
    is_admin(){
      return util.is_admin(this);
    },
    isDownloadBtn(){
      return this.ctl=='Taskcom'&&this.col.btns.Download;
    },
    has_file_url(){
      return this.Taskcom_info&&this.Taskcom_info.file_url;
    }
  },
  methods: {
    cache_models_CLAER_CACHE(){
      let url = tool.getApi(this, 'Post', 'clearCache');
      util.http.SR(this, url, {model: this.detail_info.val}, '清除缓存成功!', ()=> {
      });
    },
    cache_models_CACHE(){

      RP.showCache(this,this.detail_info.val);
    },
    setDetailInfo(){
      switch (this.ctl) {
        case 'cache_models':
          this.detail_info=logic.detail.getDetail(this, this._id,'name');
          break;
      }
    },
    myinit(){
      this.setDetailInfo();
      this.setTaskcom_info();
      this.setIsMineDownload();
    },
    setIsMineDownload(){
      if(!this.isDownloadBtn||!this.Taskcom_info)
          return;
      let vo=this.Taskcom_info;
      let _uname = vo.admin_nickname;
      let uname = this.$cookie.get('txy_name');
      this.isMineDownload= _uname == uname;
    },
    setTaskcom_info(){
      if(this.ctl!='Taskcom')
          return;
      this.Taskcom_info=logic.detail.get_not_list_field_info(this, this._id);
    },
    Whprod_info(id) {
      util.jump(this, '/page/add?ctl=WarehouseProductPriceCalendar&product_id=' + id);
    },
    Export_getFields(id) {
      let msg = 'd';
      util.showNoHide(this,msg);
    },
    Taskcom_showParams(id) {
      if(this.Taskcom_info) {
        let vo = this.Taskcom_info;
        vo.params = vo.params || {"info":"无条件"};
        if(vo.params) {
          let params = util.isString(vo.params)?JSON.parse(vo.params):vo.params;
//            tool.cl('params:', params);
          util.showMypop(this, 'info',params,{no_hide:true,isJson:true,rootObjectKey:'导出条件'});
        }
//        else{
//          util.showMsg(this,'error');
//        }
      }

    },
    Taskcom_Download(id) {
      if(this.Taskcom_info) {
        let vo = this.Taskcom_info;
        let url = vo.file_url;
        if(url) {
          window.location.href = url;
        }else{
          util.showMsg(this,'error','导出文件不存在!');
        }
      }


    },
    Hproduct_info(id) {
      util.jump(this, '/page/add?ctl=ProductQuantityCalendar&product_id=' + id);
    },
    Hproduct_tock(id) {
      util.store.push(this, 'setProductId', 'product_id', false, id, 'product');

      logic.edit.showEditPop(this, 58, ()=> {
        let vo = util.store.get(this, 'editVoModal');

        let url = tool.getApi(this, 'WarehouseProduct', 'insert');
        vo.product_id = id;
        util.getDataCom(this, url, vo, (rs) => {
          util.showMsg(this, 'success', '商品添加到仓库成功!',null,()=>{
            model.Warehouse.chooseProductAttr(this,vo.warehouse_id,id);
          })
        }, (data,msg)=> {
          msg = data ? `${data.errmsg}(${data.debug})` : msg;
          util.showMsg(this, 'error', msg);
        });


      },{},{willNext:true});
    },
    Trodetail_ADD_TAIL_LOG(id) {
      util.store.push(this, 'setProductId', 'product_id', false, id, 'product');

      logic.edit.showEditPop(this, 75, ()=> {
        let vo = util.store.get(this, 'editVoModal');

        let url = tool.getApi(this, 'WarehouseProduct', 'insert');
        vo.product_id = id;
        util.http.SR(_this, url, vo, '跟进操作成功!');


      });
    },
    editCom(id) {
      util.store.commit(this,'setIsDetail', false)
      this.toEdit(id)
    },
    toEdit(id) {
      let ctl = this.$store.state.global.current_ctl;

      let url=`/page/edit?ctl=${ctl}&_id=${id}`
      if(ctl=='control_group'){
	url = `/page/control_group/edit?id=${id}&ctl=control_group&title=权限组管理`
      }

      util.jump(this, url)
    },
  },
  props: ['col'],
  created() {
//      tool.cl('in created:' + this._id);
    this.myinit();
  },
}
</script>
<style rel="stylesheet/less" lang="less">@dir: "header/";</style>
